package net.sf.rose.business.bean.control;

import java.util.LinkedHashMap;
import java.util.Map;

import net.sf.rose.business.bean.action.Action;
import net.sf.rose.business.bean.control.judge.JudgeBean;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;

/**
 * @author fengjian
 * @since 2014-5-20
 */
public class ControlBean {

	/** 名称 */
	@Attribute
	private String name = null;

	/** 标题 */
	@Attribute
	private String text = null;

	/** 数据类型 */
	@Attribute
	private int type = 1;
	public static int DATA_TYPE_TEXT = 1; // 文本型
	public static int DATA_TYPE_TEXTAREA = 2; // 多行文本型
	public static int DATA_TYPE_INT = 3; // 普通数字
	public static int DATA_TYPE_DECIMAL = 4; // 精确数字
	public static int DATA_TYPE_DATE = 5; // 日期
	public static int DATA_TYPE_DATETIME = 6; // 日期时间
	public static int DATA_TYPE_SELECT = 7; // 下拉选择

	/** 数据格式 */
	@Attribute(required = false)
	private String format = null;
	
	/** 允许空值 */
	@Attribute
	private boolean isNull = true;

	/** 默认值 */
	@Attribute(name = "default", required = false)
	private String defaultValue = null;

	/** 最大长度 */
	@Attribute(required = false)
	private int minSize = -1;

	/** 最小长度 */
	@Attribute(required = false)
	private int maxSize = -1;

	/** 最小值 */
	@Attribute(required = false)
	private String minValue = null;

	/** 最大值 */
	@Attribute(required = false)
	private String maxValue = null;

	/** 行数 */
	@Attribute(required = false)
	private int rows = 1;

	/** 列数 */
	@Attribute(required = false)
	private int cols = 1;

	/** 数据源 */
	@Element(required = false)
	private Action dataSourceAction = null;

	/** 数据源 */
	@Element(required = false)
	private Map<String, String> dataSourceMap = null;

	/** 权限配置 */
	@Element(required = false)
	private JudgeBean judge = null;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public boolean isNull() {
		return isNull;
	}

	public void setNull(boolean isNull) {
		this.isNull = isNull;
	}

	public String getMinValue() {
		return minValue;
	}

	public void setMinValue(String minValue) {
		this.minValue = minValue;
	}

	public String getMaxValue() {
		return maxValue;
	}

	public void setMaxValue(String maxValue) {
		this.maxValue = maxValue;
	}

	public int getMinSize() {
		return minSize;
	}

	public void setMinSize(int minSize) {
		this.minSize = minSize;
	}

	public int getMaxSize() {
		return maxSize;
	}

	public void setMaxSize(int maxSize) {
		this.maxSize = maxSize;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public int getCols() {
		return cols;
	}

	public void setCols(int cols) {
		this.cols = cols;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public JudgeBean getJudge() {
		return judge;
	}

	public void setJudge(JudgeBean judge) {
		this.judge = judge;
	}

	public Action getDataSourceAction() {
		return dataSourceAction;
	}

	public void setDataSourceAction(Action dataSourceAction) {
		this.dataSourceAction = dataSourceAction;
	}

	public Map<String, String> getDataSourceMap() {
		return dataSourceMap;
	}

	public void setDataSourceMap(Map<String, String> dataSourceMap) {
		this.dataSourceMap = dataSourceMap;
	}

	/**
	 * 设置下拉式控件数据源
	 * 格式如：china=中国;england=英国;
	 * @param string 	- 数据源
	 */
	public void setDataSourceMapString(String string) {
		this.dataSourceMap = new LinkedHashMap<String, String>();
		if (string == null || string.trim().equals("")) {
			return;
		}
		String[] array = string.trim().split(";");
		for (String str : array) {
			String[] arr = str.split("=");
			this.dataSourceMap.put(arr[0], arr[1]);
		}
	}

}
